package com.spring.security.controller;

import com.spring.security.model.JsonResult;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.security.RolesAllowed;

/**
 * @author HouKunLin
 */
@RestController
@RequestMapping("/")
public class TestSecurityController {

    @Secured("ROLE_ADMIN")
    @RequestMapping("/security/secured1")
    public JsonResult secured1() {
        return JsonResult.ok();
    }

    @Secured("ROLE_User")
    @RequestMapping("/security/secured2")
    public JsonResult secured2() {
        return JsonResult.ok();
    }

    @Secured("Admin")
    @RequestMapping("/security/secured3")
    public JsonResult secured3() {
        return JsonResult.ok();
    }

    @Secured("IS_AUTHENTICATED_ANONYMOUSLY")
    @RequestMapping("/security/secured4")
    public JsonResult secured4() {
        return JsonResult.ok();
    }

    @Secured("UserAdd")
    @RequestMapping("/security/secured5")
    public JsonResult secured5() {
        return JsonResult.ok();
    }


    @RolesAllowed("ROLE_ADMIN")
    @RequestMapping("/security/rolesAllowed1")
    public JsonResult rolesAllowed1() {
        return JsonResult.ok();
    }

    @RolesAllowed("ROLE_User")
    @RequestMapping("/security/rolesAllowed2")
    public JsonResult rolesAllowed2() {
        return JsonResult.ok();
    }

    @RolesAllowed("Admin")
    @RequestMapping("/security/rolesAllowed3")
    public JsonResult rolesAllowed3() {
        return JsonResult.ok();
    }

    @PreAuthorize("isAnonymous()")
    @RequestMapping("/security/preAuthorize1")
    public JsonResult preAuthorize1() {
        return JsonResult.ok();
    }

    @PreAuthorize("hasRole('ROLE_ADMIN')")
    @RequestMapping("/security/preAuthorize2")
    public JsonResult preAuthorize2() {
        return JsonResult.ok();
    }

    @PreAuthorize("hasRole('ROLE_User')")
    @RequestMapping("/security/preAuthorize3")
    public JsonResult preAuthorize3() {
        return JsonResult.ok();
    }

    @PreAuthorize("hasRole('Admin')")
    @RequestMapping("/security/preAuthorize4")
    public JsonResult preAuthorize4() {
        return JsonResult.ok();
    }

    @PreAuthorize("hasRole('UserAdd')")
    @RequestMapping("/security/preAuthorize5")
    public JsonResult preAuthorize5() {
        return JsonResult.ok();
    }
}
